//
//  WebViewController.swift
//  AIPosts
//
//  Created by 张昭 on 2024/7/14.
//

import UIKit
import WebKit
import SnapKit

class WebViewController: BaseViewController {
    
    init(title v1: String, url v2: URL) {
        super.init(nibName: nil, bundle: nil)
        titleLabel.text = v1
        let request = URLRequest(url: v2)
        webView.load(request)
    }
    
    init(title v1: String, loadHTMLString v2: String) {
        super.init(nibName: nil, bundle: nil)
        titleLabel.text = v1
        webView.loadHTMLString(v2, baseURL: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initializeSubviews()
    }
    
    private let webView = WKWebView()
}

extension WebViewController {
    
    private func initializeSubviews() {

        webView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
        view.addSubview(webView)
        webView.snp.makeConstraints { make in
            make.bottom.equalTo(0)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(naviHeaderView.snp.bottom)
        }
    }
}
